Cricket.Results = {
				/* REQUIRED */
				Container: 'results-container',
				ListView: 'results-list-view',
				
				DetailsView: 'results-details-view',
				
				TabId: 'results',
				Data: {Success: 1, Message: ''},
				AllTeams: [],
				AllMonths: [],
				CurrentTeam: '',
				CurrentMonth: '',
				Reloaded: true,
				ParsedFeed: [],
				CurrentView: 'list',
					
				search: function() {
					//get the currently selected team
					var ResultsTeam = _gel('results-teams-dropdown').value;
					var ResultsMonth = _gel('results-months-dropdown').value;

					if(ResultsTeam !== this.CurrentTeam) {
						Cricket.Controller.Prefs.set('cricket_results_team', ResultsTeam);
						Cricket.Results.CurrentTeam = ResultsTeam;
					}
					
					if(ResultsMonth !== this.CurrentMonth) {
						Cricket.Controller.Prefs.set('cricket_results_month', ResultsMonth);
						Cricket.Results.CurrentMonth = ResultsMonth;
					}
					var Results = Cricket.Search.filter(this);
					return Results;
				},
				
				load: function() {
					//create dom
					Cricket.Results.Reloaded = true;
					//prepare AllTeams
					Cricket.Results.AllTeams = Cricket.Util.loadAllTeams(this.ParsedFeed);
					Cricket.Results.AllMonths = Cricket.Util.loadAllMonths(this.ParsedFeed);
					
					//show if current
					if(this.TabId == Cricket.Controller.getCurrentTab()) {
						this.show();
					}
				},
				show: function() {
					Cricket.Controller.activateTab(this);
				},
				showList: function() {
					
					Cricket.Controller.hideCricBuzz();
					Cricket.Results.hideInners();
					Cricket.Results.CurrentView = 'list';
					if(0 < Cricket.Live.ParsedFeed.length && false == Cricket.Controller.NotificationClosed) {
						Cricket.Controller.showLiveNotification();
					} 
					_gel('results-list-view').style.display 				= 'block';
					_gel('results-list-header').style.display 				= 'block';
					
				},	
				drawList: function() {
					var Results = this.search();
					var ListContainer = 'results-list-view';
					var ListView = document.createElement('ul');
					ListView.className = 'table-container';
						
					
					var RowCounter = 0;
							
					for(var i = 0; i < Results.length; i++ ) {
						
						if(0 === i) {
							//set the first date
							var DateShowing = new Date();
							DateShowing.setYear(Results[i].Dates.End.getFullYear());
							DateShowing.setMonth(Results[i].Dates.End.getMonth());
							DateShowing.setDate(Results[i].Dates.End.getDate());
						}
						
						//compare dates
						var DateToDisplay = new Date();
						DateToDisplay.setYear(Results[i].Dates.End.getFullYear());
						DateToDisplay.setMonth(Results[i].Dates.End.getMonth());
						DateToDisplay.setDate(Results[i].Dates.End.getDate());

						//compare
						if(0 === i || DateToDisplay.getTime() < DateShowing.getTime()) {
							//append and reate new
							DateShowing = DateToDisplay;
							if(0 !== i){
								DayListItem.appendChild(DayTable);
								ListView.appendChild(DayListItem);
								DayListItem = document.createElement('li'); 
								DateShowing = DateToDisplay;
								//reset row counter
								RowCounter = 0;
							} else {
								var DayListItem = document.createElement('li'); 
							}
							
							
							//display day
							var DayLabel = document.createElement('div');
							DayLabel.className = 'small-green-header';
							DayLabel.innerHTML = Cricket.Util.findDayLabel(DateShowing.getDay()) + ' ' + DateShowing.getDate() + ' ' + Cricket.Util.findMonthLabel(DateShowing.getMonth());
							DayListItem.appendChild(DayLabel);
							
							var DayTable = document.createElement('table');
							DayTable.className = 'full-width-table';
							DayListItem.appendChild(DayTable);
							
							var DayTableBody = document.createElement('tbody');
							DayTable.appendChild(DayTableBody);
						} 
						
						if(i === (Results.length - 1)) {
							DayListItem.appendChild(DayTable);
							ListView.appendChild(DayListItem);
						}
						
						var ResultRow = document.createElement('tr');
						ResultRow.className = (0 == RowCounter%2) ? 'row-dark' : 'row-light';
						
						//INIT INFO
						var WonBy = '';
						var WonByLabel = '';
						if(0 == Results[i].Result.WinningTeam) {
							var LoosingTeam = 0;
						} else {
							var LoosingTeam = (1 === Results[i].Result.WinningTeam) ? 2 : 1;
						}
						if('' !== Results[i].Result.WonByRuns) {
							WonBy = Results[i].Result.WonByRuns;
							WonByLabel = 'runs';
						}
						if('' !== Results[i].Result.WonByWickets) {
							WonBy = Results[i].Result.WonByWickets;
							WonByLabel = 'wkts';
						}
						
						//DRAW
						var Cell1 = document.createElement('td');
						Cell1.className = 'cell-1';
						
						var Team1Div = document.createElement('div');
						Team1Div.innerHTML = Results[i].Teams[1].shortname;
						if(1 === Results[i].Result.WinningTeam) {
							Team1Div.className = 'winner';
							Team1Div.innerHTML = 'won by ' + WonBy + ' ' + WonByLabel + ' ' + Team1Div.innerHTML;
						} else {					
							Team1Div.className = 'loser';
							if(0 === LoosingTeam) {
								Team1Div.innerHTML = '<small>Match ' + Results[i].Result.Status + '</small> ' + Team1Div.innerHTML;
							}
						}
						Cell1.appendChild(Team1Div);
						ResultRow.appendChild(Cell1);
						
						var Cell2 = document.createElement('td');
						Cell2.className = 'cell-2';
						Cell2.innerHTML = 'vs';
						ResultRow.appendChild(Cell2);
						
						var Cell3 = document.createElement('td');
						Cell3.className = 'cell-3';
						var Team2Div = document.createElement('div');
						Team2Div.innerHTML = Results[i].Teams[2].shortname;
						if(2 === Results[i].Result.WinningTeam) {
							Team2Div.className = 'winner';
							Team2Div.innerHTML += ' won by ' + WonBy + ' ' + WonByLabel;
						} else {
							Team2Div.className = 'loser';
						}
						Cell3.appendChild(Team2Div);
						ResultRow.appendChild(Cell3);
						
						var CellLast = document.createElement('td');
						CellLast.className = 'cell-last';
						var DetailsToggle = document.createElement('a');
						DetailsToggle.href = '#';
						DetailsToggle.className = 'png-link arrow-right';
						DetailsToggle.innerHTML = 'Show List';
						//DetailsToggle.innerHTML = "<img src='"+BaseUrl+"/img/arrow-right.png' />";
						DetailsToggle.onclick = Cricket.Util.generateDetailsToggle(Cricket.Results, Results[i].Id);
						CellLast.appendChild(DetailsToggle);
						ResultRow.appendChild(CellLast);
						
						DayTableBody.appendChild(ResultRow);
						
						var SpacerRow = document.createElement('tr');
						var SpacerTd = document.createElement('td');
						SpacerTd.className = 'spacer';
						SpacerRow.appendChild(SpacerTd);
						DayTableBody.appendChild(SpacerRow);
						
						RowCounter++;
					}
					//load list
					_gel(ListContainer).innerHTML = '';
					_gel(ListContainer).appendChild(ListView); 
				},
				
				drawDetails: function(MatchIndex) {
					//hide loader
					var GeneralContainer = _gel('results-details-general');
					GeneralContainer.innerHTML = '';
					var ScorecardContainer = _gel('results-details-scorecard');
					ScorecardContainer.innerHTML = '';
					var InfoContainer = _gel('results-details-info');
					InfoContainer.innerHTML = '';
					if(-1 !== MatchIndex) {
						var Match = Cricket.Results.ParsedFeed[MatchIndex];
						if(typeof Match == 'object') {
							//draw all info about match that isn't from details feed
							
							//INIT INFO
							var WonBy = '';
							var WonByLabel = '';
							if(0 == Match.Result.WinningTeam) {
								var LoosingTeam = 0;
							} else {
								var LoosingTeam = (1 === Match.Result.WinningTeam) ? 2 : 1;
							}
							if('' !== Match.Result.WonByRuns) {
								WonBy = Match.Result.WonByRuns;
								WonByLabel = 'runs';
							}
							if('' !== Match.Result.WonByWickets) {
								WonBy = Match.Result.WonByWickets;
								WonByLabel = 'wickets';
							}
							//GENERAL
							//general header
							var GeneralHeaderContainer = _gel('results-details-general-header');
							GeneralHeaderContainer.innerHTML = '';
							GeneralHeader_Main = document.createElement('div');
							GeneralHeader_Main.className = 'large-white-text-centered';
							GeneralHeaderContainer.appendChild(GeneralHeader_Main);
							
							//info link
							var GeneralHeader_InfoLinkContainer = document.createElement('div');
							GeneralHeader_InfoLinkContainer.className = 'right';
							GeneralHeader_Main.appendChild(GeneralHeader_InfoLinkContainer);
							
							var GeneralHeader_InfoLinkContainer1 = document.createElement('div');
							GeneralHeader_InfoLinkContainer1.className = 'link-container-right';
							GeneralHeader_InfoLinkContainer.appendChild(GeneralHeader_InfoLinkContainer1);
							
							var InfoLink = document.createElement('a');
							InfoLink.href='#';
							InfoLink.className = 'stretch-anchor info-inactive';
							InfoLink.id = 'results-details-info-toggle';
							InfoLink.onclick = Cricket.Results.toggleDetailsInfo;
							GeneralHeader_InfoLinkContainer1.appendChild(InfoLink);
							
							GeneralHeader_InfoLinkContainer.appendChild(document.createTextNode('Info'));
							//middle 
							var GeneralHeader_Middle = document.createElement('div');
							GeneralHeader_Middle.className = 'middle';
							GeneralHeader_Middle.innerHTML = Match.Teams[1].fullname + ' vs ' + Match.Teams[2].fullname + '<br /><small>' + Match.Series + '</small>';
							GeneralHeader_Main.appendChild(GeneralHeader_Middle);
							
							//list link
							var GeneralHeader_ListLinkContainer = document.createElement('div');
							GeneralHeader_ListLinkContainer.className = 'left';
							GeneralHeader_Main.appendChild(GeneralHeader_ListLinkContainer);
							
							var GeneralHeader_ListLinkContainer1 = document.createElement('div');
							GeneralHeader_ListLinkContainer1.className = 'link-container';
							GeneralHeader_ListLinkContainer.appendChild(GeneralHeader_ListLinkContainer1);
							
							var ListLink = document.createElement('a');
							ListLink.href='#';
							ListLink.className = 'stretch-anchor arrow-left';
							ListLink.onclick = Cricket.Util.generateShowList(Cricket.Results);
							GeneralHeader_ListLinkContainer1.appendChild(ListLink);
							
							GeneralHeader_ListLinkContainer.appendChild(document.createTextNode('Results'));
							GeneralHeader_Main.appendChild(GeneralHeader_ListLinkContainer);
							//general container
							//winner -  <div class='large-green-header-centered'>England beat Australia by 1 run</div>
							var General_WinnerDiv = document.createElement('div');
							General_WinnerDiv.className = 'large-green-header-centered';
							if(0 !== Match.Result.WinningTeam) {
								General_WinnerDiv.innerHTML = Match.Teams[Match.Result.WinningTeam].fullname + ' beat ' +Match.Teams[LoosingTeam].fullname + ' by '+WonBy + ' ' + WonByLabel;
								if(false !== Match.ScoreCard && Match.ScoreCard.CurrentScores.Revised && '' != Match.ScoreCard.CurrentScores.Revised.Reason) {
									General_WinnerDiv.innerHTML += '<br />' + Match.ScoreCard.CurrentScores.Revised.Reason;
								}
							} else {
								General_WinnerDiv.innerHTML = 'Match Status: ' + Match.Result.Status;
							}
							GeneralContainer.appendChild(General_WinnerDiv);
							
							var General_TableContainer = document.createElement('ul');
							General_TableContainer.className = 'table-container';
							GeneralContainer.appendChild(General_TableContainer);
							
							if(false !== Match.ScoreCard) {								
								//innings info info
								for(var agg = 1; agg < Match.ScoreCard.Aggregate.length; agg++) {
									General_SummaryListItem = document.createElement('li');
									General_SummaryTableHeader = document.createElement('div');
									General_SummaryTableHeader.className = 'table-header';
									
									General_SummaryHeaderDiv1 = document.createElement('div');
									General_SummaryHeaderDiv1.className = 'floatleft';
									General_SummaryHeaderDiv1.innerHTML = Match.Teams[agg].shortname + ' ' + Match.ScoreCard.Aggregate[agg].TotalRuns +' ( ' + Match.ScoreCard.Aggregate[agg].TotalOvers + ' overs)';
									General_SummaryTableHeader.appendChild(General_SummaryHeaderDiv1);
									
									if(Match.ScoreCard.Aggregate[agg].InningsNum[0]) {
										General_SummaryHeaderDiv2 = document.createElement('div');
										General_SummaryHeaderDiv2.className = 'floatright';
										
										General_SummaryHeaderLinkContainer = document.createElement('div');
										General_SummaryHeaderLinkContainer.className = 'link-container';
										General_SummaryHeaderDiv2.appendChild(General_SummaryHeaderLinkContainer);
										
										General_SummaryHeaderLink  = document.createElement('a');
										General_SummaryHeaderLink.href = '#';
										General_SummaryHeaderLink.className = 'stretch-anchor arrow-right';	
										General_SummaryHeaderLink.onclick = Cricket.Results.generateShowDetailsSocreCard(Match.ScoreCard.Aggregate[agg].InningsNum[0]);
										General_SummaryHeaderLinkContainer.appendChild(General_SummaryHeaderLink);
										General_SummaryTableHeader.appendChild(General_SummaryHeaderDiv2);
										General_SummaryTableHeader.appendChild(document.createTextNode('Scorecard'));
									} 
									
									
									
									General_SummaryListItem.appendChild(General_SummaryTableHeader);
									//spacer
									var General_SummarySpacer = document.createElement('div');
									General_SummarySpacer.className = 'spacer'; 
									General_SummaryListItem.appendChild(General_SummarySpacer);
									
									var General_SummaryTable = document.createElement('table');
									General_SummaryTable.className = 'full-width-table';
									General_SummaryListItem.appendChild(General_SummaryTable);
									
									var General_SummaryTBody = document.createElement('tbody');
									General_SummaryTBody.className = 'normal-white-text';
									General_SummaryTable.appendChild(General_SummaryTBody);
									//three summary rows
									for(var s = 0; s < 3; s++) {
										var General_SummaryRow = document.createElement('tr');
										General_SummaryRow.className = (0 == s%2) ? 'row-light' : 'row-dark';
										//batter with runs
										var BatterName = document.createElement('td');
										BatterName.className = 'cell-1';
										if(Match.ScoreCard.Aggregate[agg].BatsmenSorted[s]) {
											BatterName.innerHTML = Match.ScoreCard.Aggregate[agg].BatsmenSorted[s].FullName;
										}
										General_SummaryRow.appendChild(BatterName);
										
										var BatterValue = document.createElement('td');
										BatterValue.className = 'cell-2';
										if(Match.ScoreCard.Aggregate[agg].BatsmenSorted[s]) {
											BatterValue.innerHTML = Match.ScoreCard.Aggregate[agg].BatsmenSorted[s].Runs;
										}
										General_SummaryRow.appendChild(BatterValue);
										
										var BowlerName = document.createElement('td');
										BowlerName.className = 'cell-3';
										if(Match.ScoreCard.Aggregate[agg].BowlersSorted[s]) {
											BowlerName.innerHTML = Match.ScoreCard.Aggregate[agg].BowlersSorted[s].FullName;
										}
										General_SummaryRow.appendChild(BowlerName);
										
										var BowlerValue = document.createElement('td');
										BowlerValue.className = 'cell-last';
										if(Match.ScoreCard.Aggregate[agg].BowlersSorted[s]) {
											BowlerValue.innerHTML = Match.ScoreCard.Aggregate[agg].BowlersSorted[s].RunsOff + '/' + Match.ScoreCard.Aggregate[agg].BowlersSorted[s].Wickets;
										}
										General_SummaryRow.appendChild(BowlerValue);
										
										General_SummaryTBody.appendChild(General_SummaryRow);
										
										var Spacer = document.createElement('tr');
										Spacer.className = 'spacer';
										General_SummaryTBody.appendChild(Spacer);
										
									}
									
									
									
									General_TableContainer.appendChild(General_SummaryListItem);
								}
							} else {
								MessageItem = document.createElement('li');
								General_TableContainer.appendChild(MessageItem);
								Message = document.createElement('div');
								Message.className = 'message';
								Message.innerHTML = 'Detailed match information is not currently available';
								MessageItem.appendChild(Message);
							}
							Cricket.Util.drawScoreCard(Match, ScorecardContainer, 'results');

							
							//INFO
							var InfoList = document.createElement('ul');
							InfoList.className = 'table-container';
							InfoContainer.appendChild(InfoList);
							
							var InfoTableListItem = document.createElement('li');
							InfoList.appendChild(InfoTableListItem);
							
							Info_Table = document.createElement('table');
							Info_Table.id = 'info-table';
							Info_Table.className = 'full-width-table';
							InfoTableListItem.appendChild(Info_Table);
							
							var VenueRow = document.createElement('tr');
							VenueRow.id = 'info-venue';
							VenueRow.className = 'row-dark';
							var LabelTd = document.createElement('td');
							LabelTd.className = 'cell-1';
							LabelTd.innerHTML = 'Venue:';
							VenueRow.appendChild(LabelTd);
							
							var ValueTd = document.createElement('td');
							ValueTd.className = 'cell-last';
							ValueTd.innerHTML = Match.Venue;
							VenueRow.appendChild(ValueTd);
							Info_Table.appendChild(VenueRow);
							
							var SpacerRow = document.createElement('tr');
							SpacerRow.className = 'spacer';
							Info_Table.appendChild(SpacerRow);
							
							var DaysRow = document.createElement('tr');
							DaysRow.id = 'info-days';
							DaysRow.className = 'row-light';
							
							var LabelTd = document.createElement('td');
							LabelTd.className = 'cell-1';
							LabelTd.innerHTML = 'Days:';
							DaysRow.appendChild(LabelTd);
							
							var ValueTd = document.createElement('td');
							ValueTd.className = 'cell-last';
							var StartString = (Match.Dates.Start.getDate()) + '/'+ (Match.Dates.Start.getMonth() + 1) + '/' +Match.Dates.Start.getFullYear();
							var EndString = (Match.Dates.End.getDate()) + '/'+ (Match.Dates.End.getMonth() + 1) + '/' +Match.Dates.End.getFullYear();
							ValueTd.innerHTML = StartString +' to ' +EndString;
							DaysRow.appendChild(ValueTd);
							Info_Table.appendChild(DaysRow);
							
							var SpacerRow = document.createElement('tr');
							SpacerRow.className = 'spacer';
							Info_Table.appendChild(SpacerRow);
							
							if(false !== Match.ScoreCard) {
								var UmpiresRow = document.createElement('tr');
								UmpiresRow.id = 'info-umpires';
								UmpiresRow.className = 'row-dark normal-white-text';
								
								var LabelTd = document.createElement('td');
								LabelTd.className = 'cell-1';
								LabelTd.innerHTML = 'Umpires:';
								UmpiresRow.appendChild(LabelTd);
								
								var ValueTd = document.createElement('td');
								ValueTd.className = 'cell-last';
								ValueTd.innerHTML = Match.ScoreCard.MatchInfo.Umpires[1].FullName +' and ' +Match.ScoreCard.MatchInfo.Umpires[2].FullName;
								UmpiresRow.appendChild(ValueTd);
								Info_Table.appendChild(UmpiresRow);
								
								var SpacerRow = document.createElement('tr');
								SpacerRow.className = 'spacer';
								Info_Table.appendChild(SpacerRow); 
								
								var SpacerRow = document.createElement('tr');
								SpacerRow.className = 'spacer';
								Info_Table.appendChild(SpacerRow); 
								
								var TossRow = document.createElement('tr');
								TossRow.id = 'info-toss';
								TossRow.className = 'row-dark normal-white-text';
								Info_Table.appendChild(TossRow);
								
								var TossTd = document.createElement('td');
								TossTd.colSpan = '2';
								var Decision = '';
								switch(Match.ScoreCard.MatchInfo.Toss.Decision) {
									case 'batting':
									case 'Batting':
										Decision = 'bat';
										break;
									case 'fielding':
									case 'Fielding':
										Decision = 'field';
										break;
								}
								if('' != Decision) {
									TossTd.innerHTML = '<strong>'+Match.ScoreCard.MatchInfo.Toss.Winner+'</strong> won the toss and elected to <strong>' +Decision+'.</strong>';
								}
								TossRow.appendChild(TossTd);
								
								
								var CloseLinkContainer = document.createElement('li');
								CloseLinkContainer.className = 'info-close';
								InfoList.appendChild(CloseLinkContainer);
							
								var CloseLink = document.createElement('a');
								CloseLink.href='#';
								CloseLink.innerHTML ='close';
								CloseLink.className = 'info-close-link';
								CloseLink.onclick = Cricket.Results.toggleDetailsInfo;
								CloseLinkContainer.appendChild(CloseLink);
							
								
								
								if(Match.MoreInfo && '' != Match.MoreInfo) {
									Cricket.Controller.updateCricBuzz(Match.MoreInfo);
								} 
							}						
							Cricket.Results.showDetailsGeneral();
						} 				
					} else {
						Cricket.Messages.show('Match could not be found');
					}
				},
				
				generateShowDetailsSocreCard: function(PreSelected) {
					return function() {
						Cricket.Results.showDetailsSocreCard(PreSelected);
						return false;
					}
				},
				showDetailsGeneral: function() {
					Cricket.Results.hideInners();
					Cricket.Results.CurrentView 							= 'details';
					_gel('results-details-view').style.display 				= 'block';
					_gel('results-details-general-header').style.display 	= 'block';
					_gel('results-details-general').style.display 			= 'block';
				},
				
				showDetailsSocreCard: function(PreSelected) {
					Cricket.Results.CurrentView 							= 'details';
					Cricket.Results.hideInners();
					_gel('results-details-view').style.display 				= 'block';
					_gel('results-details-scorecard-header').style.display 	= 'block';
					_gel('results-details-scorecard').style.display 		= 'block';
					//select the correct one
					for(var o = 0; o < _gel('results-scorecard-dropdown').options.length; o++) {
						if(_gel('results-scorecard-dropdown').options[o].value == PreSelected) {
							_gel('results-scorecard-dropdown').options[o].selected = 'selected';
							break;
						}
					}
					Cricket.Results.showInnings(PreSelected);
				},
				
				toggleDetailsInfo: function()  {
					if('block' == _gel('results-details-info').style.display) {
						Cricket.Results.showDetailsGeneral();
						_gel('results-details-info-toggle').className = 'info-inactive';
					} else {
						Cricket.Results.showDetailsInfo();
						_gel('results-details-info-toggle').className = 'info-active';
					}
				},
				
				showDetailsInfo: function() {
					Cricket.Results.hideInners();
					Cricket.Results.CurrentView 							= 'details';
					_gel('results-details-view').style.display 				= 'block';
					_gel('results-details-general-header').style.display 	= 'block';
					_gel('results-details-info').style.display 				= 'block';
					
				},
				
				showInnings: function(InningsNum) {
					//hide all
					AllInnings = _gel('results-details-scorecard').getElementsByTagName('ul');
					for(var i=0; i<AllInnings.length; i++) {
						AllInnings[i].style.display = 'none';
					}
					_gel('results-details-scorecard-innings-'+InningsNum).style.display = 'block';
				},
				
				hideInners: function() {
					_gel('results-live-notification').style.display 		= 'none';
					_gel('results-list-view').style.display 				= 'none';
					_gel('results-list-header').style.display 				= 'none';
					_gel('results-details-view').style.display 				= 'none';
					_gel('results-details-general').style.display 			= 'none';
					_gel('results-details-scorecard').style.display 		= 'none';
					_gel('results-details-info').style.display 				= 'none';
					_gel('results-details-general-header').style.display 	= 'none';
					_gel('results-details-scorecard-header').style.display 	= 'none';
				},
				
				loadError: function() {
					Cricket.Results.Data.Success = 0;
					Cricket.Results.Data.Message = 'Information on Results is currently unavailable';
					//show if current
					if(this.TabId == Cricket.Controller.getCurrentTab()) {
						this.show();
					} 
				}
			}